<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')" align-center :close-on-click-modal="false">
		<el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="110px" label-position="right">
            <el-form-item label="转出人员" prop="turn_staff">
                <el-select v-model="form.turn_staff" placeholder="请选择" style="width:100%" filterable>
                    <el-option v-for="item in humList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="转出日期" prop="turn_date">
				<el-date-picker v-model="form.turn_date" type="date" placeholder="请选择日期" style="width: 100%;" :value-format="'YYYY-MM-DD'"></el-date-picker>
			</el-form-item>
            <el-form-item label="转出原因" prop="turn_reason">
				<el-input v-model="form.turn_reason" clearable type="textarea" placeholder="请输入转出原因"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '转出人员',
				edit: '派工',
				show: '查看'
			},
            dialog: {
				save: false,
			},
			visible: false,
			isSaveing: false,
			//表单数据
			form: {
				id: "",
				turn_staff: "",
				turn_reason: "",
				turn_date: "",
			},
            name:'',
			//验证规则
			rules: {
				turn_staff: [
					{ required: true, message: '请选择转出人员' }
				],
			},
            humList:[],
		}
	},
	mounted() {
        // this.getHum()
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		//加载树数据
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = [];
					res = await this.$API.production.turn.post(this.form);
					this.isSaveing = false;
					if (res.code == 1) {
						this.$emit('success', this.form, this.mode)
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", { type: 'error' })
					}
				} else {
					return false;
				}
			})
		},
		//表单注入数据
		setData(data) {
			this.form.id = data.id
            this.getHum(data.work.work_team_id)
		},
        async getHum(e){
            var res = await this.$API.all.getAdmin.get({is_page:0,dept_id:e});
            this.humList = res.data
        },
	}
}
</script>

<style></style>
